/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.its.dd2.Bl;

import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import mx.its.dd2.Dao.UserDaoLocal;
import mx.its.dds2.modelo.User;
import mx.its.dds2.modelo.User;
import mx.its.dsw2.farmacia.enumeracion.EstadoRegistro;

/**
 *
 * @author Piter
 */
@Stateless
public class UserBl implements UserBlLocal {
    @EJB
    private UserDaoLocal userDao;
    

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
      @Override
    public EstadoRegistro Register(User user) {
         if(userDao.findDuplicity(user)){
             return EstadoRegistro.INCOMPLETO;
         }else{
             userDao.create(user);
             return EstadoRegistro.COMPLETO;
         }
        
          
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

    @Override
    public EstadoRegistro modify(User user) {
        if(user.getUserPK()==null || userDao.find(user.getUserPK())==null){
            return EstadoRegistro.INCOMPLETO;
         }
    else{
    userDao.edit(user);
    return EstadoRegistro.COMPLETO;
        }
    }

    @Override
    public EstadoRegistro delete(User user) {
         if(user.getUserPK()==null || userDao.find(user.getUserPK())==null){
            return EstadoRegistro.INCOMPLETO;
         }
    else{
    userDao.remove(user);
    return EstadoRegistro.COMPLETO;
        }
    }

    @Override
    public List<User> getAll() {
        return userDao.findAll();
    }
    


}
